package cn.sym.org.controller;

import cn.sym.basic.util.AjaxResult;
import cn.sym.basic.util.PageList;
import cn.sym.org.aspect.anno.Operation;
import cn.sym.org.domain.SystemDictionaryDetail;
import cn.sym.org.domain.SystemDictionaryType;
import cn.sym.org.query.DepartmentQuery;
import cn.sym.org.query.SystemDictionaryDetailQuery;
import cn.sym.org.service.ISystemDictionaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/DicDetail")
public class DictionaryDetailController {
    @Autowired
    private ISystemDictionaryDetailService iSystemDictionaryDetailService;

    /**
     * 新增和修改
     * @param systemDictionaryDetail
     * @return
     */
    @PutMapping
    public AjaxResult addAndUpdate(@RequestBody SystemDictionaryDetail systemDictionaryDetail){
        try {
            if (systemDictionaryDetail.getId()==null){
                iSystemDictionaryDetailService.add(systemDictionaryDetail);
            }else{
                iSystemDictionaryDetailService.update(systemDictionaryDetail);
            }
            return new AjaxResult();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("操作失败！！！");
        }
    }

    /**
     * 单条删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id){
        try {
            iSystemDictionaryDetailService.remove(id);
            return AjaxResult.my();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("网络错误，请稍后再试！！1");
        }
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @Operation("批量删除")
    @PatchMapping
    public AjaxResult remove(@RequestBody List<Long> ids){
        try {
            iSystemDictionaryDetailService.removeMore(ids);
            return AjaxResult.my();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("网络错误，请稍后再试！！1");
        }
    }
    /**
     * 通过id查询
     */
    @GetMapping("/{id}")
    public SystemDictionaryDetail queryById(@PathVariable("id") Long id){
        return iSystemDictionaryDetailService.queryById(id);
    }
    /**
     * 查询所有
     */
    @GetMapping
    public List<SystemDictionaryDetail> queryAll(){
        System.out.println("哈哈哈哈哈!!!!!");
        return iSystemDictionaryDetailService.queryAll();
    }
    /**
     * 查询无限极部门树
     * @return
     */
   /* @GetMapping("/tree")
    public List<SystemDictionaryType> queryTree(){
        return isystemDictionaryTypeService.queryTree();
    }*/
    /**
     * 高级查询
     */
    @PostMapping
    public PageList<SystemDictionaryDetail> queryPage(@RequestBody SystemDictionaryDetailQuery query){
        System.out.println("前端请求参数"+query);
        return iSystemDictionaryDetailService.queryPage(query);
    }
}
